
import javax.swing.*;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;

import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.sql.*;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.Vector;
import java.util.Date;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

/**
 * This graphic design for this page by Lanny Wilson
 * Code and part of page layout by Fraser Hogg
 * 
 * 
 * 
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class PkgProd extends javax.swing.JFrame {

	/**
	 * 
	 */
	private static final long serialVersionUID = 7121455980368227085L;
	private JLabel lblLogo;
	private JPanel block1;
	private JPanel divider2;
	private JButton btnIncnt;
	private JButton btnHome;
	private JPanel divider1;
	private JTable JTbPkg;
	private JButton btnLogout;
	private JScrollPane jScrollPane1;
	private JTextField txtName;
	private JButton btnViewSup;
	private JButton btnViewPkg;
	private JLabel lblSup;
	private JComboBox jCmbSup;
	private JComboBox jCmbProd;
	private JButton btnReset;
	private JLabel lblPkgName;
	private JButton btnDel;
	private JButton btnNew;
	private JTextField txtEDate;
	private JTextField txtSDate;
	private JTextField txtCom;
	private JTextField txtPrice;
	private JLabel lblComm;
	private JLabel lblPrice;
	private JLabel lblDesc;
	private JLabel lblEndDate;
	private JLabel lblStDate;
	private JLabel lblName;
	private JButton btnAgent;
	private JLabel imgHome;
	//saves most recently selected pkgId
	private int pkgId;
	//remembers which view table is using
	private boolean pkgView;

	//declare table data and headers
	private Vector<String> colNames = new Vector<String>();
	private Vector<Vector> dataRows = new Vector<Vector>();
	SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
	DecimalFormat decF = new DecimalFormat("0.00");
	// populate products drop down IF a supplier exists
	// or gets passed a supplier ID IF one is selected, then finding pertinent product(s)
	// on page generation prodId of -1 is hard coded and all products with suppliers are grabbed
	public Vector<String> getProd(int supId) throws ClassNotFoundException, SQLException {
		// TODO Auto-generated method stub
		Vector<String> prod = new Vector<String>();
		ResultSet rs = null;
		Statement stmt = getCon();
		if(supId<0){
			rs = stmt.executeQuery("SELECT DISTINCT p.ProductId, p.ProdName "+
								"FROM Products p INNER JOIN Products_Suppliers a ON p.ProductId = a.ProductId");
		}
		else {
			rs = stmt.executeQuery("SELECT p.ProductId, p.ProdName FROM Products p "+
								"INNER JOIN Products_Suppliers a ON p.ProductId = a.ProductId "+
					"WHERE a.SupplierId ="+supId);
		}
		while (rs.next())
		{
			prod.add(rs.getString("ProductId") + "-" + rs.getString("ProdName"));
		}
		stmt.close();
		return prod;
	}
	// gets passed a product ID IF one is selected, 
	// on page generation prodId of -1 is hard coded and all Suppliers are grabbed
	public Vector<String> getSup(int ProdId) throws ClassNotFoundException, SQLException {
		Vector<String> sup = new Vector<String>();
		Statement stmt = getCon();
		ResultSet rs = null;
		if(ProdId > -1){
			try{
			rs = stmt.executeQuery("SELECT s.SupplierId, s.SupName FROM Suppliers s "+
								"INNER JOIN Products_Suppliers a ON s.SupplierId = a.SupplierId "+
								"WHERE a.ProductId ="+ProdId);
			}
			catch(SQLException ex){
				System.out.println(ex);
			}
		}
		else{
			try{
			rs = stmt.executeQuery("SELECT s.SupplierId, s.SupName FROM Suppliers s INNER JOIN Products_Suppliers a ON s.SupplierId = a.SupplierId");
			}
			catch(SQLException ex){
				System.out.println(ex);
			}
		}
		while (rs.next())
		{
			sup.add(rs.getString("SupplierId") + "-" + rs.getString("SupName"));
		}
		stmt.close();
		return sup;
	}
	//connection getter
	private  Statement getCon() throws ClassNotFoundException, SQLException
	{
		Class.forName("com.mysql.jdbc.Driver");
		Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/travelexperts", "root","root");
		if (!conn.isClosed())
			System.out.println("Successfully connected.");
		return conn.createStatement();
	}
	//gets headers for jtable from metadata
	public void loadColData() throws SQLException, ClassNotFoundException
	{
		pkgView = true;
		pkgId = 0;
		Statement stmt = getCon();
		ResultSet rs = stmt.executeQuery("SELECT * FROM Packages");
		ResultSetMetaData rsmd = rs.getMetaData();
	
		for (int i = 1; i <= rsmd.getColumnCount(); i++)
		{
			colNames.add(rsmd.getColumnName(i));
		}
		stmt.close();
	}
	//loads the packages row data of to jtable
	public void loadRowData() 
	{
		pkgView=true;
		try {
			ResultSet rs;
			Statement stmt = getCon();
			rs = stmt.executeQuery("SELECT * FROM Packages");
			ResultSetMetaData rsmd = rs.getMetaData();
			
			while (rs.next())
			{
				//get value, format and add as string to vector for table data
				Vector<String> row = new Vector<String>(); 
				int PkgId = rs.getInt(1);
				row.add(String.valueOf(PkgId));
				String PkgName = rs.getString(2);
				row.add(PkgName);
				Date PkgStart = rs.getDate(3);
				row.add(df.format(PkgStart));
				Date PkgEnd = rs.getDate(4);
				row.add(df.format(PkgEnd));
				String PkgDesc = rs.getString(5);
				row.add(PkgDesc);
				double PkgBase = rs.getDouble(6);
				row.add(decF.format(PkgBase));
				double PkgCom = rs.getDouble(7);
				row.add(decF.format(PkgCom));
				dataRows.add(row);
				//pkg.JTbPkgModel.
			}
			stmt.close();
		} catch (SQLException e) {
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}	
	}
	// new vectors as using the last ones twice sketchy when switching table models
		private Vector<String> prodCol= new Vector<String>();
		private Vector<Vector> prodData = new Vector<Vector>();
	// combines loadRowData and loadColData but grabs products associate with a given pkg
	// whose Id is saved in parameter pkgID upon package selection
	// If pkgId is 0 (invalid) then all products with a supplier are shown
	public void loadProd() throws SQLException, ClassNotFoundException{
		Statement stmt = getCon();
		ResultSet rs = null;
		prodCol.clear();
		prodData.clear();
		if(pkgId>0){
			try{
			rs = stmt.executeQuery("SELECT p.ProdName, p.ProductId, s.SupName, s.SupplierId "+
								"FROM Suppliers s, Products_Suppliers a, Products p, Packages_Products_Suppliers b "+
								"WHERE p.ProductId = a.ProductId AND s.SupplierId = a.SupplierId "+
								"AND a.ProductSupplierId = b.ProductSupplierId AND b.PackageId ="+pkgId);
			}
			catch (SQLException e) {
				// TODO Auto-generated catch block
				System.out.println(e+ "this failed in loadProd");
				e.printStackTrace();
			}
		}
		else{
			try{
				rs = stmt.executeQuery("SELECT p.ProdName product, p.ProductId pId, s.SupName supplier, " +
									"s.SupplierId sId FROM Suppliers s, Products_Suppliers a, Products p, "+
									"Packages_Products_Suppliers b WHERE p.ProductId = a.ProductId "+
									"AND s.SupplierId = a.SupplierId AND a.ProductSupplierId = b.ProductSupplierId");
				}
				catch (SQLException e) {
					// TODO Auto-generated catch block
					System.out.println(e+ "this failed in loadProd");
					e.printStackTrace();
				}
		}
		ResultSetMetaData rsmd = rs.getMetaData();
	
		for (int i = 1; i <= rsmd.getColumnCount(); i++)
		{
			prodCol.add(rsmd.getColumnName(i));
		}
		while (rs.next()){
			Vector<String> row = new Vector<String>();
			for (int i = 1; i <= rsmd.getColumnCount(); i++)
			{
				row.add(rs.getString(i));
			}
			prodData.add(row);
		}
		stmt.close();
	}
	//currently copied over from pkg.java, 
	//to be redone to add a product_supplier to package in package_products_suppliers 
	public void prodAdd() throws ClassNotFoundException, SQLException, NumberFormatException
	{
		if(pkgId>0){
			Statement stmt = getCon();
			String sql="";
			String[] prodSt = jCmbProd.getSelectedItem().toString().split("-");
			int prod = Integer.parseInt(prodSt[0]);
			String[] supSt = jCmbSup.getSelectedItem().toString().split("-");
			int sup = Integer.parseInt(supSt[0]);
			System.out.println(sup+ " "+ prod);
			ResultSet rs = null; 
			try{
			rs = stmt.executeQuery("SELECT ProductSupplierId "+
					"FROM Products_Suppliers "+
					"WHERE ProductId ="+ prod +" AND SupplierId ="+ sup );
			rs.next();
			System.out.println(rs.getString(1));
			sql = "INSERT INTO Packages_Products_Suppliers (PackageId, ProductSupplierId) "+
						"VALUES ("+pkgId+", "+ rs.getString(1)+")";
			stmt.executeUpdate(sql);
			}
			catch(SQLException Ex){
				System.out.println(sql + Ex);
			}
			finally {
				stmt.close();
			}
		}
	}
	// deletes selected products_suppliers from package
	public boolean prodDelete() throws ClassNotFoundException, SQLException, NumberFormatException
	{
		if(pkgId>0){
			Statement stmt = getCon();
			String prod = (String) JTbPkg.getValueAt(JTbPkg.getSelectedRow(), 1);
			String sup =(String) JTbPkg.getValueAt(JTbPkg.getSelectedRow(), 3);
			ResultSet rs = stmt.executeQuery("SELECT ProductSupplierId "+
					"FROM Products_Suppliers "+
					"WHERE ProductId ="+ prod +" AND SupplierId ="+ sup);
			rs.next();
			try {
				stmt.executeUpdate("DELETE FROM Packages_Products_Suppliers WHERE PackageId = " + pkgId
						+" AND ProductSupplierId="+ rs.getString(1));
			} 
			catch (Exception e) {
				System.out.println("Delete table error!");
				return false;
			}
			finally{
				stmt.close();
				//reset(); taken out to allow quicker multiple deletes
			}
		}
		else{
			return false;
		}
		return true;
	}
	//resets after a insert or delete
	public void reset(){
		//TODO add your code for btnReset.actionPerformed
		btnDel.setEnabled(false);
		jCmbProd.setSelectedIndex(-1);
		jCmbSup.setSelectedIndex(-1);
		JTbPkg.repaint();
		pkgId = 0;
		cleartext();
	}
	//clears text fields
	private void cleartext()
	{
		txtName.setText("");
		txtSDate.setText("");
		txtEDate.setText("");
		txtCom.setText("");
		txtPrice.setText("");
	}
	
	/**
	* Auto-generated main method to display this JFrame
	*/
	public static void main(String[] args) {
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				PkgProd inst = new PkgProd();
				inst.setLocationRelativeTo(null);
				inst.setVisible(true);
			}
		});
	}
	
	public PkgProd() {
		super();
		setResizable(false);
		initGUI();
	}
	
	private void initGUI() {
		try {
			setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
			getContentPane().setLayout(null);
			getContentPane().setBackground(new java.awt.Color(255,255,255));
			this.setTitle("Travel Experts Package Products");
			{
				lblLogo = new JLabel();
				getContentPane().add(lblLogo);
				lblLogo.setBounds(24, 12, 257, 78);
				lblLogo.setBackground(new java.awt.Color(255,0,0));
				lblLogo.setIcon(new ImageIcon(getClass().getClassLoader().getResource("images/TravelLogo.jpg")));
			}
			{
				lblName = new JLabel();
				getContentPane().add(lblName);
				lblName.setText("Name");
				lblName.setBounds(14, 117, 77, 15);
				lblName.setFont(new java.awt.Font("SansSerif",1,12));
				lblName.setHorizontalAlignment(SwingConstants.RIGHT);
			}
			{
				txtName = new JTextField();
				txtName.setEditable(false);
				getContentPane().add(txtName);
				txtName.setBounds(103, 114, 192, 20);
				txtName.setFont(new java.awt.Font("SansSerif",0,12));
				txtName.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
				txtName.setBackground(new java.awt.Color(255,255,255));
			}
			{
				lblStDate = new JLabel();
				getContentPane().add(lblStDate);
				lblStDate.setText("Start Date");
				lblStDate.setBounds(14, 147, 80, 13);
				lblStDate.setFont(new java.awt.Font("SansSerif",1,12));
				lblStDate.setHorizontalAlignment(SwingConstants.RIGHT);
			}
			{
				txtSDate = new JTextField();
				txtSDate.setEditable(false);
				getContentPane().add(txtSDate);
				txtSDate.setBounds(103, 143, 125, 20);
				txtSDate.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
				txtSDate.setFont(new java.awt.Font("SansSerif",0,12));
				txtSDate.setBackground(new java.awt.Color(255,255,255));
			}
			{
				lblEndDate = new JLabel();
				getContentPane().add(lblEndDate);
				lblEndDate.setText("End Date");
				lblEndDate.setBounds(14, 174, 80, 14);
				lblEndDate.setFont(new java.awt.Font("SansSerif",1,12));
				lblEndDate.setHorizontalAlignment(SwingConstants.RIGHT);
			}
			{
				txtEDate = new JTextField();
				txtEDate.setEditable(false);
				getContentPane().add(txtEDate);
				txtEDate.setBounds(103, 172, 125, 20);
				txtEDate.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
				txtEDate.setBackground(new java.awt.Color(255,255,255));
			}
			{
				lblPrice = new JLabel();
				getContentPane().add(lblPrice);
				lblPrice.setText("Base Price");
				lblPrice.setBounds(14, 202, 80, 17);
				lblPrice.setFont(new java.awt.Font("SansSerif",1,12));
				lblPrice.setHorizontalAlignment(SwingConstants.RIGHT);
			}
			{
				txtPrice = new JTextField();
				txtPrice.setEditable(false);
				getContentPane().add(txtPrice);
				txtPrice.setBounds(103, 201, 73, 20);
				txtPrice.setFont(new java.awt.Font("SansSerif",0,12));
				txtPrice.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
				txtPrice.setBackground(new java.awt.Color(255,255,255));
			}
			{
				lblComm = new JLabel();
				getContentPane().add(lblComm);
				lblComm.setText("Commission");
				lblComm.setBounds(-7, 231, 101, 18);
				lblComm.setFont(new java.awt.Font("SansSerif",1,12));
				lblComm.setHorizontalAlignment(SwingConstants.RIGHT);
			}
			{
				txtCom = new JTextField();
				txtCom.setEditable(false);
				getContentPane().add(txtCom);
				txtCom.setBounds(103, 230, 73, 20);
				txtCom.setFont(new java.awt.Font("SansSerif",0,12));
				txtCom.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
				txtCom.setBackground(new java.awt.Color(255,255,255));
			}
			{
				lblDesc = new JLabel();
				getContentPane().add(lblDesc);
				lblDesc.setText("Products");
				lblDesc.setBounds(1, 261, 93, 17);
				lblDesc.setFont(new java.awt.Font("SansSerif",1,12));
				lblDesc.setHorizontalAlignment(SwingConstants.RIGHT);
			}
			{
				lblSup = new JLabel();
				getContentPane().add(lblSup);
				lblSup.setText("Suppliers");
				lblSup.setBounds(8, 292, 87, 17);
				lblSup.setFont(new java.awt.Font("SansSerif",1,12));
				lblSup.setHorizontalAlignment(SwingConstants.RIGHT);
			}
			{
				btnNew = new JButton();
				btnNew.addMouseListener(new MouseAdapter() {
					@Override
					public void mouseClicked(MouseEvent arg0) {
						try {
							prodAdd();
						} catch (NumberFormatException | ClassNotFoundException
								| SQLException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}
						
					}
				});
				getContentPane().add(btnNew);
				btnNew.setText("Add");
				btnNew.setBounds(316, 124, 100, 22);
				btnNew.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
				btnNew.setFont(new java.awt.Font("SansSerif",1,12));
			}
			{
				btnDel = new JButton();
				btnDel.addMouseListener(new MouseAdapter() {
					@Override
					public void mouseClicked(MouseEvent e) {
						//System.out.println("btnDelete.actionPerformed");
						
						if (JTbPkg.getSelectedRow() == -1)
						{
							JOptionPane.showMessageDialog(null, "You must select a row first");
						}
						else
						{
						try {
							if (prodDelete())
							{
								//dataRows.clear();
								loadProd();
								JTbPkg.repaint();
								JOptionPane.showMessageDialog(null, "deleted successfully");
								btnNew.setEnabled(true);
								btnDel.setEnabled(false);
							}
							else
							{
								JOptionPane.showMessageDialog(null, "delete failed");
							}
						} 
						catch (ClassNotFoundException ex) {
							ex.printStackTrace();
						} 
						catch (SQLException ex) {
							// TODO Auto-generated catch block
							ex.printStackTrace();
						}
						}
					}
				});
				getContentPane().add(btnDel);
				btnDel.setText("Delete");
				btnDel.setBounds(316, 162, 100, 22);
				btnDel.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
				btnDel.setFont(new java.awt.Font("SansSerif",1,12));
				btnDel.setEnabled(false);
			}
			{
				btnReset = new JButton();
				btnReset.addMouseListener(new MouseAdapter() {
					@Override
					public void mouseClicked(MouseEvent e) {
						System.out.println("btnReset.actionPerformed, event");
						//TODO add your code for btnReset.actionPerformed
						btnNew.setEnabled(false);
						btnDel.setEnabled(false);
						jCmbProd.setSelectedIndex(-1);
						jCmbSup.setSelectedIndex(-1);
						pkgId = 0;
						cleartext();
					}
				});
				getContentPane().add(btnReset);
				btnReset.setText("Reset");
				btnReset.setBounds(316, 200, 100, 22);
				btnReset.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
				btnReset.setFont(new java.awt.Font("SansSerif",1,12));
			}
			{
				btnViewPkg = new JButton();
				btnViewPkg.addMouseListener(new MouseAdapter() {
					@Override
					public void mouseClicked(MouseEvent arg0) {
						if(!pkgView){
							colNames.clear();
							try {
								loadColData();
							} catch (ClassNotFoundException | SQLException e) {
								// TODO Auto-generated catch block
								e.printStackTrace();
							}
							dataRows.clear();
							loadRowData();
							TableModel JTbPkgModel = 
									new DefaultTableModel(dataRows,colNames);
							JTbPkg.setModel(JTbPkgModel);
							JTbPkg.repaint();
							cleartext();
							btnDel.setEnabled(false);
						}
					}
				});
				getContentPane().add(btnViewPkg);
				btnViewPkg.setText("View Packages");
				btnViewPkg.setBounds(316, 238, 100, 22);
				btnViewPkg.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
				btnViewPkg.setFont(new java.awt.Font("SansSerif",1,10));
			}
			{
				btnViewSup = new JButton();
				btnViewSup.addMouseListener(new MouseAdapter() {
					@Override
					public void mouseClicked(MouseEvent arg0) {			
						pkgView = false;
						try {
							loadProd();
						} catch (ClassNotFoundException | SQLException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
							System.out.println(e + "this failed at loadProd2");
						}
						TableModel JTbProdModel = new DefaultTableModel(prodData,prodCol);
						JTbPkg.setModel(JTbProdModel);
						JTbPkg.repaint();
					}
				});
				getContentPane().add(btnViewSup);
				btnViewSup.setText("View Products");
				btnViewSup.setBounds(316, 276, 100, 22);
				btnViewSup.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
				btnViewSup.setFont(new java.awt.Font("SansSerif",1,10));
			}
			{
				ComboBoxModel jCmbProdModel = 
						new DefaultComboBoxModel(getProd(-1));
				jCmbProd = new JComboBox();
				jCmbProd.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent arg0) {
						if(jCmbProd.getSelectedIndex()>=0){
							String[] prod = jCmbProd.getSelectedItem().toString().split("-");
							int prodId = Integer.parseInt(prod[0]);
							Vector<String> sups = null;
							try {
								sups = getSup(prodId);
							} catch (ClassNotFoundException e) {
								// TODO Auto-generated catch block
								e.printStackTrace();
							} catch (SQLException e) {
								// TODO Auto-generated catch block
								e.printStackTrace();
							}
							ComboBoxModel jCmbSelSupModel = new DefaultComboBoxModel(sups);
							jCmbSup.setModel(jCmbSelSupModel);
							jCmbSup.setSelectedIndex(-1);
						}
					}
				});
				getContentPane().add(jCmbProd);
				jCmbProd.setModel(jCmbProdModel);
				jCmbProd.setBounds(103, 259, 192, 23);
				jCmbProd.setBackground(new java.awt.Color(255,255,255));
				jCmbProd.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
				jCmbProd.setFont(new java.awt.Font("SansSerif",0,12));
				jCmbProd.setSelectedIndex(-1);

			}
			{
				ComboBoxModel jCmbSupModel = new DefaultComboBoxModel(getSup(-1));
				jCmbSup = new JComboBox();				
				getContentPane().add(jCmbSup);
				jCmbSup.setModel(jCmbSupModel);
				jCmbSup.setBounds(103, 289, 192, 23);
				jCmbSup.setBackground(new java.awt.Color(255,255,255));
				jCmbSup.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
				jCmbSup.setFont(new java.awt.Font("SansSerif",0,12));
				jCmbSup.setSelectedIndex(-1);
			}
			{
				divider1 = new JPanel();
				getContentPane().add(divider1);
				divider1.setBounds(425, 26, 5, 300);
				divider1.setBackground(new java.awt.Color(0,0,0));
			}
			{
				divider2 = new JPanel();
				getContentPane().add(divider2);
				divider2.setBounds(690, 26, 5, 300);
				divider2.setBackground(new java.awt.Color(0,0,0));
			}
			{
				btnAgent = new JButton();
				getContentPane().add(btnAgent);
				btnAgent.setIcon(new ImageIcon(getClass().getClassLoader().getResource("images/btnAgent.jpg")));
				btnAgent.setBounds(526, 26, 70, 300);
				btnAgent.setBackground(new java.awt.Color(255,255,255));
				btnAgent.addMouseListener(new MouseAdapter() {
					public void mouseClicked(MouseEvent evt) {
						System.out.println("btnAgent.mouseClicked, event="+evt);
						//TODO add your code for btnAgent.mouseClicked
						agent inst = new agent();
						inst.setLocationRelativeTo(null);
						inst.setVisible(true);
						PkgProd.this.dispose();
					}
				});
			}
			{
				btnHome = new JButton();
				getContentPane().add(btnHome);
				btnHome.setIcon(new ImageIcon(getClass().getClassLoader().getResource("images/btnHm.jpg")));
				btnHome.setBounds(444, 26, 70, 300);
				btnHome.addMouseListener(new MouseAdapter() {
					public void mouseClicked(MouseEvent evt) {
						System.out.println("btnHome.mouseClicked, event="+evt);
						//TODO add your code for btnHome.mouseClicked
						home inst = new home();
						inst.setLocationRelativeTo(null);
						inst.setVisible(true);
						PkgProd.this.dispose();
					}
				});
			}
			{
				btnIncnt = new JButton();
				getContentPane().add(btnIncnt);
				btnIncnt.setIcon(new ImageIcon(getClass().getClassLoader().getResource("images/btnPkg.jpg")));
				btnIncnt.setBounds(608, 26, 70, 300);
				btnIncnt.addMouseListener(new MouseAdapter() {
					public void mouseClicked(MouseEvent evt) {
						System.out.println("btnIncnt.mouseClicked, event="+evt);
						pkg inst = new pkg();
						inst.setLocationRelativeTo(null);
						inst.setVisible(true);
						PkgProd.this.dispose();
					}
				});
			}
			{
				block1 = new JPanel();
				getContentPane().add(block1);
				block1.setBackground(new java.awt.Color(73,84,163));
				block1.setBounds(695, 101, 184, 225);
			}
			{
				imgHome = new JLabel();
				getContentPane().add(imgHome);
				imgHome.setBounds(0, 101, 425, 225);
				imgHome.setIcon(new ImageIcon(getClass().getClassLoader().getResource("images/incentBk.jpg")));
			}
			{
				loadColData();
				loadRowData();
				jScrollPane1 = new JScrollPane();
				getContentPane().add(jScrollPane1);
				jScrollPane1.setBounds(12, 338, 855, 140);
				jScrollPane1.setOpaque(true);
				{
					TableModel JTbPkgModel = 
							new DefaultTableModel(dataRows,colNames);
					JTbPkg = new JTable();
					
					JTbPkg.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
					jScrollPane1.setViewportView(JTbPkg);
					jScrollPane1.setOpaque(true);
					jScrollPane1.setBackground(new java.awt.Color(255,255,255));
					jScrollPane1.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
					JTbPkg.setModel(JTbPkgModel);
					JTbPkg.setBounds(6, 338, 754, 140);
					JTbPkg.setOpaque(true);
					JTbPkg.setFont(new java.awt.Font("SansSerif",0,10));
					JTbPkg.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
						
						public void valueChanged(ListSelectionEvent e) {
							if(pkgView&& 7==JTbPkg.getColumnCount() ){
								//Populate form with record
								txtCom.setText((String)JTbPkg.getValueAt(JTbPkg.getSelectedRow(), 6));
								txtEDate.setText((String)JTbPkg.getValueAt(JTbPkg.getSelectedRow(), 3));
								txtName.setText((String)JTbPkg.getValueAt(JTbPkg.getSelectedRow(), 1));
								txtPrice.setText((String)JTbPkg.getValueAt(JTbPkg.getSelectedRow(), 5));
								txtSDate.setText((String)JTbPkg.getValueAt(JTbPkg.getSelectedRow(), 2));
								String temp = (String)JTbPkg.getValueAt(JTbPkg.getSelectedRow(), 0);
								pkgId = Integer.parseInt(temp);
							}
							else if(!pkgView && pkgId >0){
								btnDel.setEnabled(true);
							}
						}
					});
				}
			}
			{
				btnLogout = new JButton();
				getContentPane().add(btnLogout);
				btnLogout.setText("Logout");
				btnLogout.setBorderPainted(false);
				btnLogout.setFont(new java.awt.Font("SansSerif",0,10));
				btnLogout.setOpaque(false);
				btnLogout.setBounds(799, 4, 69, 20);
				btnLogout.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
				btnLogout.addMouseListener(new MouseAdapter() {
					public void mouseClicked(MouseEvent evt) {
						System.out.println("btnHome.mouseClicked, event="+evt);
						//TODO add your code for btnHome.mouseClicked
						home inst = new home();
						inst.setLocationRelativeTo(null);
						inst.setVisible(true);
						PkgProd.this.dispose();
					}
				});
			}
			{
				lblPkgName = new JLabel();
				getContentPane().add(lblPkgName);
				lblPkgName.setText("PRODUCTS");
				lblPkgName.setBounds(707, 70, 160, 25);
				lblPkgName.setFont(new java.awt.Font("SansSerif",1,24));
				lblPkgName.setHorizontalAlignment(SwingConstants.CENTER);
			}
			pack();
			this.setSize(890, 519);
		} catch (Exception e) {
		    //add your error handling code here
			e.printStackTrace();
		}
	}
}